package client.comm.baoding.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import client.comm.commlib.base.BaseLoadmoreAdapter
import client.comm.commlib.base.BindingViewHoder
import client.comm.baoding.R
import client.comm.baoding.api.bean.CateGoods
import client.comm.baoding.api.bean.TxJl
import client.comm.baoding.databinding.LayoutTxjlitemBinding
import client.comm.commlib.base.BasePagingAdapter
import client.comm.commlib.base.PagingViewHoder

import com.bumptech.glide.RequestManager
import com.google.gson.Gson

class TxjlPagingAdapter(val context: Context, val manager: RequestManager) :
    BasePagingAdapter<TxJl.Withdraw>(object : DiffUtil.ItemCallback<TxJl.Withdraw>() {
        val g = Gson()

        override fun areItemsTheSame(
            oldItem: TxJl.Withdraw,
            newItem: TxJl.Withdraw
        ): Boolean {
            return oldItem.id.equals(newItem.id)
        }

        override fun areContentsTheSame(
            oldItem: TxJl.Withdraw,
            newItem: TxJl.Withdraw
        ): Boolean {
            return g.toJson(oldItem).equals(g.toJson(newItem))
        }
    }) {

    override fun bindItem(holder: PagingViewHoder, t: Any) {
        val binding = holder.binding as LayoutTxjlitemBinding
        val bean = t as TxJl.Withdraw
        binding.bean = bean

        binding.payType = bean.to_status_str
        if (bean.status === 0) {
            binding.setStatus("审核中")
            binding.stateTv.setTextColor(context.resources!!.getColor(R.color.fontRed))
        } else if (bean.status === 1) {
            binding.setStatus("成功")
            binding.stateTv.setTextColor(context.resources!!.getColor(R.color.fontGreen))
        } else if (bean.status === 2) {
            binding.setStatus("失败")
            binding.stateTv.setTextColor(context.resources!!.getColor(R.color.fontRed))
        }
    }

    override fun getItemLayout(): Int {
        return R.layout.layout_txjlitem
    }
}